/* I (David P Shenba) licenses this file to you under the Apache License, 
 * Version 2.0 (the "License"); you may not use this 
 * file except in compliance with the License.  You may 
 * obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var demoBeanSize = 0;

function preparePage() {
	enableById('bean'+(eval(demoBeanSize)-1)+'Button');
}

function addBeanSection() {
	if(demoBeanSize > 0) {
		disableById('bean'+(eval(demoBeanSize)-1)+'Button');
	}
	var htmlText = '<b>Bean '+(eval(demoBeanSize)+1)+':</b> ';
	htmlText += '<button type="button" id="bean'+demoBeanSize+'Button" '; 
	htmlText += 'onclick="removeBeanContent(\''+demoBeanSize+'\');">Remove</button> <br/>';
	htmlText += '<table><tr><td>Name</td><td>:</td>';
	htmlText += '<td><input type="text" name="demoBean['+demoBeanSize+'].name"></td>';
	htmlText += '</tr><tr><td>Age</td><td>:</td>';
	htmlText += '<td><input type="text" name="demoBean['+demoBeanSize+'].age" value=""></td>';
	htmlText += '</tr><tr><td>Sex</td><td>:</td>';
	htmlText += '<td><input type="radio" name="demoBean['+demoBeanSize+'].sex" value="Male"> Male ';
	htmlText += '<input type="radio" name="demoBean['+demoBeanSize+'].sex" value="Female"> Female</td>';
	htmlText += '</tr><tr><td>Relationship Status</td><td>:</td>';
	htmlText += '<td><select name="demoBean['+demoBeanSize+'].married"><option value="Single">Single</option>';
	htmlText += '<option value="Married">Married</option><option value="Divorced">Divorced</option>';
	htmlText += '<option value="Widowed">Widowed</option></select></td></tr></table><hr/>';
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id','bean'+demoBeanSize+'Content');
	newDiv.innerHTML = htmlText;
	document.getElementById("beanArryContent").appendChild(newDiv);
	demoBeanSize++;
}

function removeBeanContent(beanIndex) {
	if(beanIndex > 0) {
		enableById('bean'+(eval(beanIndex)-1)+'Button');
	}
	document.getElementById("beanArryContent").removeChild(document.getElementById('bean'+beanIndex+'Content'));
	demoBeanSize--;
}

function disableById(elemId) {
	document.getElementById(elemId).disabled = true;
}

function enableById(elemId) {
	document.getElementById(elemId).disabled = false;
}